package cn.edu.neusoft.mall.Dao.impl;

import cn.edu.neusoft.framework.db.JDBCTemplate;
import cn.edu.neusoft.framework.db.RowMapper;
import cn.edu.neusoft.mall.Dao.commentDao;
import cn.edu.neusoft.mall.entity.Comment;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class commentDaoImpl implements commentDao {
    RowMapper<Comment> rowMapper=new RowMapper<Comment>() {
        @Override
        public Comment mapRow(ResultSet rs, int rowNum) throws SQLException {
            Comment comment=new Comment();
            comment.setNickname(rs.getString("nickname"));
            comment.setContent(rs.getString("content"));
            return comment;
        }
    };
    @Override
    public List<Comment> getCommentList() {
        String sql = "select * from comments";
        return JDBCTemplate.query(sql,rowMapper,null);
    }

    @Override
    public int insertComment(String name, String comment) {
        String sql = "INSERT INTO comments (nickname, content) VALUES (?, ?);";
        return JDBCTemplate.update(sql, name, comment);
    }
}
